package com.template;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;

import com.template.utils.TStringUtils;

public class TIService {

	public static void createXMLFile(String tableName, String packageName,List<TableBean>columnList,List<TableBean>priList, List<TableBean>noPriList, String folderName, String path) {
		String className = TStringUtils.tableName2ClassName(tableName);
	    String attrName = TStringUtils.columnName2Attr(tableName);
	    String str = "";
	    
	    str +="package "+packageName+".service;\r\n\r\n";
	    str +="import java.util.HashMap;\r\n";
	    str +="import java.util.List;\r\n";
	    str +="import org.springframework.stereotype.Component;\r\n";
	    str +="import "+packageName+".entity."+className+";\r\n";
	    str +="import "+packageName+".util.ParameterMap;\r\n\r\n";
	    str +="@Component\r\n";
	    str +=" public interface I"+className+"Service {\r\n";
	    str +="       public List<ParameterMap> get"+className+"List();\r\n";
	    str +="       public HashMap<String, Object> add(ParameterMap pm);\r\n";
	    str +="       public HashMap<String,Object> edit(ParameterMap pm); \r\n";
	    
	    String type = "String";
		if ("int".equals(priList.get(0).getDataType())) {
			type = "long";
		} else if ("date".equals(priList.get(0).getDataType())
				|| "datetime".equals(priList.get(0).getDataType())
				|| "timestamp".equals(priList.get(0).getDataType())) {
			type = "Date";
		}
	    
	    str +="       public HashMap<String, Object> del("+type+" "+priList.get(0).getColumnName()+"); \r\n";
	    str +="       public "+className+" get"+className+"Info(ParameterMap pm);\r\n";
	    str +=" }\r\n";
	    
	    
		try {
			String allPath = path+"\\I"+className+"Service.java";
			OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(allPath),"UTF-8");
			output.write(str);
			output.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
